package com.mdd.admin.controller.refund;

import com.github.binarywang.wxpay.exception.WxPayException;
import com.mdd.admin.service.log.IOrderRefundLogService;
import com.mdd.admin.service.refund.IOrderRefundService;
import com.mdd.admin.validate.refund.OrderRefundPageParam;
import com.mdd.admin.vo.log.OrderRefundLogDetailVo;
import com.mdd.admin.vo.refund.OrderRefundListVo;
import com.mdd.admin.vo.refund.StatisticsOrderRefundCountVo;
import com.mdd.admin.vo.refund.StatisticsOrderRefundVo;
import com.mdd.common.core.PageResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * 订单退款管理
 */
@Api(tags = "订单退款管理")
@RestController
@RequestMapping("api/refund")
public class OrderRefundController {

    @Resource
    IOrderRefundService iOrderRefundService;

    @Resource
    private IOrderRefundLogService iOrderRefundLogService;

    /**
     * 订单退款列表
     *
     * @param params 搜索参数
     * @return Object
     * @author slien
     */
    @ApiOperation(value = "订单退款管理 - 列表")
    @PostMapping("/list")
    public PageResult<OrderRefundListVo> list(@RequestBody OrderRefundPageParam params) {
        return iOrderRefundService.list(params);
    }

    /**
     * @return java.lang.Object
     * @Author slien
     * @Description 统计订单状态的数据
     * @Date 11:47 2022/10/11
     * @Param []
     **/
    @ApiOperation(value = "订单退款管理 - 统计数量")
    @PostMapping("/statistics/count")
    public StatisticsOrderRefundCountVo statisticsCount(@RequestBody OrderRefundPageParam params) {
        return iOrderRefundService.statisticsCount(params);
    }

    /**
     * @return java.lang.Object
     * @Author slien
     * @Description 统计订单状态的数据
     * @Date 11:47 2022/10/11
     * @Param []
     **/
    @ApiOperation(value = "订单退款管理 - 统计金额")
    @GetMapping("/statistics/amount")
    public StatisticsOrderRefundVo statisticsAmount() {
        return iOrderRefundService.statisticsAmount();
    }

    /**
     * 订单退款日志详情
     *
     * @param refundId 主键ID
     * @return Object
     */
    @ApiOperation(value = "订单退款管理 - 退款详情")
    @GetMapping("/detail")
    public List<OrderRefundLogDetailVo> detail(@RequestParam("refundId") Long refundId) {
        return iOrderRefundLogService.detail(refundId);
    }

    /**
     * 订单重新退款
     *
     * @param refundId 主键ID
     * @return Object
     */
    @ApiOperation(value = "订单退款管理 - 重新退款")
    @GetMapping("/repeat")
    public void repeatRefund(@RequestParam("refundId") Long refundId) throws WxPayException {
        iOrderRefundService.repeatRefund(refundId);
    }

    /**
     * 部分退款-后台人员确定
     */
    @ApiOperation(value = "部分退款-后台人员确定")
    @GetMapping("/rebates")
    public void rebates(@RequestParam("refundId") Long refundId,@RequestParam("reviewStatus")Integer reviewStatus) throws WxPayException {
        iOrderRefundService.rebates(refundId,reviewStatus);
    }

}
